package com.threeti.jiayusms.framework.domain.support;

import javax.persistence.MappedSuperclass;

import org.apache.commons.lang.StringUtils;

import com.threeti.jiayusms.framework.domain.AbstractCustomKeyDomainEntity;
import com.threeti.jiayusms.framework.domain.DomainEntity;

/**
 * 实体采用字符串作为简单的自定义键<p/>
 *
 * @author Jay Meng
 */
@MappedSuperclass
@SuppressWarnings("serial")
public abstract class DefaultCustomKeyDomainEntity extends AbstractCustomKeyDomainEntity<String> {
  private String customId;

  public DefaultCustomKeyDomainEntity(String customId) {
    super();
    this.customId = customId;
  }

  @Override
  public String getCustomId() {
    return customId;
  }

  @Override
  public void setCustomId(String customId) {
    this.customId = customId;
  }
  
  @Override
  protected final boolean sameAs(DomainEntity other) {
    DefaultCustomKeyDomainEntity otherCustomEntity = (DefaultCustomKeyDomainEntity)other;
    if (!StringUtils.isEmpty(customId) && !StringUtils.isEmpty(otherCustomEntity.getCustomId())) 
      return customId.equals(otherCustomEntity.getCustomId());
    return super.sameAs(other);
  }

  protected DefaultCustomKeyDomainEntity() {
  }
}
